<?php


namespace app\common\behavior;


use think\Db;

class User
{
    //判断用户VIP时间
    public function vip()
    {
        $model = new \app\common\model\User();
        $list = $model->lock(true)->where('level', 'not in', ['5','0'])->select();

        Db::startTrans();
        try {
            foreach ($list as $item) {
                if($item->viptime <= time()) {
                    $item->save([
                        'viptime' => '',
                        'level' => 0,
                    ]);
                    \app\common\model\Message::setMessage($item->id,"您的VIP已到期",'/pages/mine/vip');
                }
            }
            Db::commit();
        }catch (ValidateException|PDOException|Exception $e) {
            Db::rollback();
            echo $e->getMessage();
        }
    }
}